package com.liuyucheng.tcpudp.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author LiuYuCheng
 * @date 2023年06月06日 22:48
 */
public class TCPReceiveDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10086);
        while(true){
            //接收数据
            Socket accept = ss.accept();
            //创建字节数组接收
            byte[] bytes = new byte[1024];
            //获取字节输入流读数据
            InputStream input = accept.getInputStream();
            int len = input.read(bytes);
            System.out.println("发送方信息：" + InetAddress.getLocalHost().getHostAddress());
            //输出数据
            System.out.println(new String(bytes, 0, len));
//            accept.close();
        }
    }
}